package com.project.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author(王思翰)
 * @Description(类的描述)
 * @Date(创建时间) 2021/7/28 9:32
 */
@RestController
@RequestMapping("cookie")
public class CookieController {

    @RequestMapping("test")
    public  String test(HttpServletResponse response){
        //创造一个cookie对象，底层类似于map集合
        Cookie c1=new Cookie("name","tom");
        Cookie c2=new Cookie("id","008");
        //设置cookie过期时间
        c2.setMaxAge(200000);

        //将cookie信息，发送给客户端
        response.addCookie(c1);
        response.addCookie(c2);
        return "ok";
    }

    @RequestMapping("mytest")
    public String mytest(HttpServletRequest request){
        Cookie[] cookies=request.getCookies();
        for (Cookie cookie : cookies) {
            System.out.println(cookie.getName()+"   "+cookie.getValue());
        }
        return "hello";
    }
}
